<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>周期收费用户</title>
	<link rel="stylesheet" type="text/css" href="../../rs/plugins/easyui/themes/metro/easyui.css">
	<link rel="stylesheet" type="text/css" href="../../rs/plugins/easyui/themes/icon.css">
	<link href="../../rs/css/bootstrap.min14ed.css" rel="stylesheet">
	<link href="../../rs/css/style.min862f.css" rel="stylesheet">
	<script type="text/javascript" src="../../rs/plugins/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="../../rs/plugins/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../rs/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
	<script src="../../rs/js/jquery.cookie.js"></script>
	<script src="../../rs/js/common_qj.js"></script>
	<style>
		html,body{ margin:0px; height:100%;}
	</style>
</head>
<body >
<table id="table" class="easyui-datagrid"  style="width:100%;height:100%;padding: 10px;"
			data-options="
			rownumbers:true,
			singleSelect:'false',
			method:'get' ,
			toolbar:'#easyui_toolbar',
			fit:true,
			fitColumns:true,
			remoteSort:false,
	        fit:'true'">
		<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true"></th>
				<th data-options="field:'mc',align:'left',width:40,formatter:formatId,sortable:true"> 商户信息</th>
				<th data-options="field:'lxr',align:'left',width:15,sortable:true" > 联系人</th>
				<th data-options="field:'sj',align:'center',width:20,sortable:true" > 手机</th>
				<th data-options="field:'fwmc',align:'center',width:30,sortable:true" > 服务名称</th>
				<th data-options="field:'jxs',align:'center',width:20,sortable:true"> 经销商</th>
				<th data-options="field:'zt',align:'center',width:15,styler:cellStyler,sortable:true"> 状态</th>
				<th data-options="field:'bz',align:'center',width:30,sortable:true"> 备注</th>
				<th data-options="field:'yx_rq',align:'center',width:20,sortable:true"> 到期日期</th>


			</tr>
		</thead>
	</table>

	<div id="easyui_toolbar" region="north" border="false"
	  style="height: 45px;padding: 2px 5px; ">
		<div style="float: left;">
			<button style="float:left; margin-right:5px; border-radius: 0px; "  class="btn btn-danger" onclick="data_remove()" >
				<i class="glyphicon glyphicon-trash"></i>
			</button>
		</div>
		<div style="float: left;">
			<button style="float:left;margin-left:5px;  border-radius: 0px;" class="btn btn-success" onclick="open_modal()"  >
				<i class="glyphicon glyphicon-plus"></i> 新增
			</button>
		</div>
		<div id="tb" class="input-group" style="float: right; margin-right: 10px;width:350px">
			<input type="text" class="form-control" id="searchtext" placeholder="输入搜索关键字" value="">
			<div class="input-group-btn">
				<button type="button" class="btn btn-white dropdown-toggle" onclick="do_search()" style="border-radius: 0px;">
					搜索
				</button>
				<!--<button type="button" class="btn btn-default" onclick="f_sheard()" style="margin-left: 8px;
		border-radius:0px;">
					刷新
				</button>-->
			</div>
		</div>
	</div>

<div style="display: none" id="open_edit">
	<form id="edit_from">
					<div class="input-group" style="display: none;">
						<div class="input-group-btn">
							<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">rid</button>
						</div>
						<input type="text" class="form-control" name="rid" required="true"  >
					</div>
					<div class="input-group" style="padding: 20px 20px 8px 20px;">
						<div class="input-group-btn">
							<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 商户信息</button>
						</div>
						<input type="text" class="form-control" name="mc" required="true"  >
					</div>
					<div class="input-group" style="padding: 0px 20px 8px 20px;">
						<div class="input-group-btn">
							<button style="margin-right: -2px;height: 34px;" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 联系人&nbsp;&nbsp;&nbsp;&nbsp;</button>
						</div>
						<input type="text" class="form-control "   name="lxr">
					</div>
					<div class="input-group" style="padding: 0px 20px 8px 20px;">
						<div class="input-group-btn">
							<button style="margin-right: -2px;height: 34px;" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 经销商&nbsp;&nbsp;&nbsp;&nbsp;</button>
						</div>
						<input type="text" class="form-control " name="jxs">
					</div>
					<div class="input-group" style="padding: 0px 20px 8px 20px;">
						<div class="input-group-btn">
							<button style="margin-right: -2px;height: 34px;" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 手&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;机</button>
						</div>
						<input type="text" class="form-control " name="sj">
					</div>
					<div class="input-group" style="padding: 0px 20px 8px 20px;">
						<div class="input-group-btn">
							<button style="margin-right: -2px;height: 34px;" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址</button>
						</div>
						<input type="text" class="form-control " name="dz">
					</div>
					<div class="input-group" style="padding: 0px 20px 8px 20px;">
						<div class="input-group-btn">
							<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 服务名称</button>
						</div>
						<input type="text" class="form-control " name="fwmc">
					</div>


					<div class="input-group" style="padding: 0px 20px 8px 20px;">
						<div class="input-group-btn">
							<button style="margin-right: -2px;height: 34px;" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态</button>
						</div>
						<select class="form-control"   name="zt">
							<option >有效</option>
							<option >暂停</option>
							<option >试用</option>
							<option >停用</option>
							<option >删除</option>
						</select>
					</div>
					<div class="input-group" style="padding: 0px 20px 8px 20px;">
						<div class="input-group-btn">
							<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 到期日期</button>
						</div>
						<input style="max-width: 270px;" type="text" class="form-control layer-date" placeholder="请选择日期" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" name="yx_rq">
					</div>
					<div class="input-group" style="padding: 0px 20px 8px 20px;">
						<div class="input-group-btn">
							<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 最后付款日期</button>
						</div>
						<input style="max-width: 270px;" type="text" class="form-control layer-date" placeholder="请选择日期" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" name="ff_rq">
					</div>
					<div class="input-group" style="padding: 0px 20px 8px 20px;">
						<div class="input-group-btn">
							<button style="margin-right: -2px;height: 34px;" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"> 备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注</button>
						</div>
						<input type="text" class="form-control " name="bz">
					</div>


		<div style="position: absolute;width:100%;bottom:0px;padding: 0px 20px 8px 20px;">
			<button type="reset" id="reset" style="display:none;">reset</button>
			<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"
					style="background-color: #e2e2e2;" onclick="layer.closeAll()">返回
			</button>
			<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"
					style="background-color: #f54141;color: white;float: right" id="save_do">保存
			</button>
		</div>
	</form>
</div>

<!--页面加载缓冲图标-->
<div id='loadingDiv' style="position:absolute;z-index:1000;top:0px; left:0px;
	width:100%;height:100%;background:white;text-align: center;">
	<h1 style="top: 30%; position: relative;">
		<img src="../../rs/img/loading-2.gif" /><br>
	</h1>
</div>
<script>

	/*页面加载缓冲*/
	function closeLoading() {
		$("#loadingDiv").fadeOut("normal", function () {
			$(this).remove();
		});
	}
	var no;
	$.parser.onComplete = function () {
		if (no) clearTimeout(no);
		no = setTimeout(closeLoading, 1000);
	}

	var sign = URLencode($.cookie('sign'));
	 
	$(function(){
		if(sign==="undefined"){
			window.location.href = "login.html";
		}
		f_sheard();
		var getdata;
	});
	//判断 企业权限&加载数据
	function f_sheard(){
		$.ajax({
			type: "post",
			url:G_url+'doi/see/sycy',
			data: 'sign=' + sign,
			dataType: "json",
			success: function (usedata){
				getdata=usedata;
				if (usedata.ok) {
					$('#table').datagrid({
						data: usedata.data
					});
				}else{
					window.location.href = 'login.html';
				}
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	}





	$('#searchtext').bind('keypress',function(event){
		if(event.keyCode == "13") {
			do_search();
		}
	});

	function do_search(){
		var gjc=$('#searchtext').val(); //搜索关键词
		if(gjc==""){
			$('#table').datagrid({
				data: getdata
			});
		}else{
			var newdata=[];
			for(var i=0;i<getdata.data.length;i++){
				str=transform(getdata.data[i]).join(',');
				row=str.indexOf(gjc);
				if(row>=0){
					newdata.push(getdata.data[i]);
				}
			}

			$('#table').datagrid({
				data: newdata
			});
		}
	}
	function transform(obj){
		var arr = [];
		for(var item in obj){
			arr.push(obj[item]);
		}
		return arr;
	}


	function cellStyler(value,row,index){
		if (value =="有效"){
			return 'color:green;';
		}else if(value =="停用"){
			return 'color:red;';
		}else if(value =="暂停"){
			return 'color:#bfbfbf;';
		}else if(value =="试用"){
			return 'color:#f8ac59;';
		}else if(value =="删除"){
			return 'color:red;';
		}
	}


	function open_modal(){

		$("#open_edit").show();
		$('#reset').click();
		layer.open({
			title: "新增",
			type: 1,
			skin: 'layui-layer-rim',//加上边框
			offset: '40px',//top顶部偏移
			area: ['400px', '540px'], //宽高
			shadeClose: true,
			content: $('#edit_from')
		});

	}


	/*删除操作*/
	function data_remove(){
		var rows = $('#table').datagrid('getSelections');
		if(rows.length!=0){
			layer.confirm('确定删除吗？', {
				title: [''],
				btn: ['确定', '取消'] //按钮
			}, function do_remove() {
				var rids = $.map(rows, function (row) {
					return row.rid
				});
				$.ajax({
					type: "post",
					url: G_url+'doi/del/sycy?sign='+sign,
					data:"rid="+rids,
					dataType: "json",
					success: function (result) {
						if (result.ok) {
							layer.closeAll();
							f_sheard();
							layer.msg(result.msg);

						} else {
							layer.msg(result.msg);
						}
					},
					error: function (XMLHttpRequest, textStatus, errorThrown) {
						//alert(errorThrown);
					}
				});
			});
		}else{
			layer.msg("请先选择！");
		}
	}
	//删除操作

	$("#save_do").on("click",function(){
		var layer_title=$('.layui-layer-title').text();
		var rid=$("input[name='rid']").val();
		var mc=$("input[name='mc']").val();
		var fwmc=$("input[name='fwmc']").val();
		var lxr=$("input[name='lxr']").val();
		var sj=$("input[name='sj']").val();
		var dz=$("input[name='dz']").val();
		var jxs=$("input[name='jxs']").val();
		var zt=$("select[name='zt']").val();
		var bz=$("input[name='bz']").val();
		var yx_rq=$("input[name='yx_rq']").val();
		var ff_rq=$("input[name='ff_rq']").val();
		if(layer_title=="新增"){
			$.ajax({
				type: "post",
				url:G_url+'doi/add/sycy'+'?'+'sign='+sign,
				data:"mc="+mc+"&lxr="+lxr+"&dz="+dz+"&jxs="+jxs+"&sj="+sj+"&zt="+zt+"&fwmc="+fwmc+"&bz="+bz+"&yx_rq="+yx_rq+"&ff_rq="+ff_rq,
				dataType: "json",
				success: function (result){
					if (result.ok){
						$('#table').datagrid('appendRow',{
							mc: mc,
							lxr: lxr,
							dz: dz,
							jxs: jxs,
							sj: sj,
							zt: zt,
							fwmc: fwmc,
							bz: bz,
							yx_rq: yx_rq,
							ff_rq: ff_rq
						});
					} else {
						layer.msg(result.msg);
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
				}
			});
			layer.closeAll();

		}else if(layer_title=="修改"){

			$.ajax({
				type: "post",
				url:G_url+'doi/edit/sycy'+'?'+'sign='+sign,
				data:"rid="+rid+"&mc="+mc+"&lxr="+lxr+"&dz="+dz+"&jxs="+jxs+"&sj="+sj+"&zt="+zt+"&fwmc="+fwmc+"&bz="+bz+"&yx_rq="+yx_rq+"&ff_rq="+ff_rq,
				dataType: "json",
				success: function (result){
					if (result.ok){
						$('#table').datagrid('updateRow',{
							index: rowindex,
							row: {
								mc: mc,
								lxr: lxr,
								dz: dz,
								jxs: jxs,
								sj: sj,
								zt: zt,
								fwmc: fwmc,
								bz: bz,
								yx_rq: yx_rq,
								ff_rq: ff_rq
							}
						});
						layer.msg(result.msg);
					} else {
						layer.msg(result.msg);
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
				}
			});
			f_sheard();
			layer.closeAll();
		}
	});
	var rowindex;
	function open_edit(r){
		var rowdata=$('#table').datagrid('getData');
		var row=rowdata.rows[r];
		rowindex=r;
		if (row){
			$("#open_edit").show();
			$('#edit_from').form('load',row);
			var bh=$("input[name='bh']").val();
			$("#dizhi").val("http://sl.deeyi.com/dy/pj/deeyi/login.html?"+bh);
			layer.open({
				title: "修改",
				type: 1,
				offset: '40px',//top顶部偏移
				skin: 'layui-layer-rim', //加上边框
				area: ['400px', '540px'], //宽高
				shadeClose: true,
				content: $('#edit_from')
			});

		}
	}
	function formatId(value,rowData,rowIndex){
		return "<a href='javascript:void(0)' onclick='open_edit("+rowIndex+");'>"+value+"</a>";
	}



</script>
<script src="../../rs/plugins/layer/layer.min.js"></script>
<script src="../../rs/plugins/laydate/laydate.js"></script>
<script src="../../rs/js/bootstrap.js"></script>
<script src="../../rs/plugins/md5.js"></script>
</body>
</html>